package com.bh.web.controller.extend;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.extend.domain.JcDbProduct;
import com.bh.extend.service.IJcDbProductService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户货品Controller
 * 
 * @author slx
 * @date 2023-06-15
 */
@RestController
@RequestMapping("/extend/dbProduct")
public class JcDbProductController extends BaseController
{
    @Autowired
    private IJcDbProductService jcDbProductService;

    /**
     * 查询客户货品列表
     */
    @ApiOperation("查询客户货品列表")
    @PreAuthorize("@ss.hasPermi('extend:dbProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcDbProduct jcDbProduct)
    {
        startPage();
        List<JcDbProduct> list = jcDbProductService.selectJcDbProductList(jcDbProduct);
        return getDataTable(list);
    }

    /**
     * 导出客户货品列表
     */
    @PreAuthorize("@ss.hasPermi('extend:dbProduct:export')")
    @Log(title = "客户货品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcDbProduct jcDbProduct)
    {
        List<JcDbProduct> list = jcDbProductService.selectJcDbProductList(jcDbProduct);
        ExcelUtil<JcDbProduct> util = new ExcelUtil<JcDbProduct>(JcDbProduct.class);
        util.exportExcel(response, list, "客户货品数据");
    }

    /**
     * 获取客户货品详细信息
     */
    @ApiOperation("获取客户货品详细信息")
    @PreAuthorize("@ss.hasPermi('extend:dbProduct:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcDbProductService.selectJcDbProductById(id));
    }

    /**
     * 新增客户货品
     */
    @ApiOperation("新增客户货品")
    @PreAuthorize("@ss.hasPermi('extend:dbProduct:add')")
    @Log(title = "客户货品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcDbProduct jcDbProduct)
    {
        return toAjax(jcDbProductService.insertJcDbProduct(jcDbProduct));
    }

    /**
     * 修改客户货品
     */
    @ApiOperation("修改客户货品")
    @PreAuthorize("@ss.hasPermi('extend:dbProduct:edit')")
    @Log(title = "客户货品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcDbProduct jcDbProduct)
    {
        return toAjax(jcDbProductService.updateJcDbProduct(jcDbProduct));
    }

    /**
     * 删除客户货品
     */
    @ApiOperation("删除客户货品")
    @PreAuthorize("@ss.hasPermi('extend:dbProduct:remove')")
    @Log(title = "客户货品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcDbProductService.deleteJcDbProductByIds(ids));
    }
}
